import { CommentLoadCondition, CommentPage } from "@/model/CommentModel"
import { Resource, ResourceDetail, ResourcePage, SearchCondition } from "@/model/ResourceModels"
import axios from "axios"

export const loadResourcePaceAPI = async (searchCondition: SearchCondition):
    Promise< ResourcePage | null > => {
         console.log(`API加载第 ${searchCondition.pageIndex} 页的数据...`)
    try {
        // 发送搜索资源请求
        const response = await axios.post('/api/resource/getResourcePage', 
            searchCondition, 
            { headers: { 'Content-Type': 'application/json' } }
        )
        console.log("后端返回的数据：", response.data)              //调试
        return response.data
    } catch (error) {
        // 搜索资源失败，捕获异常
        console.error('获取资源数据失败:', error)
        return null 
    }
}

export const loadResourceDetailAPI = async (resourceId: number):
    Promise< ResourceDetail | null > => {
         console.log(`API加载资源id为 ${resourceId} 的详细数据...`)
    try {
        // 发送搜索资源请求
        const response = await axios.post('/api/resource/getResourceDetail', 
            resourceId , 
            { headers: { 'Content-Type': 'application/json' } }
        )
        console.log("后端返回的数据：", response.data)              //调试
        return response.data
    } catch (error) {
        // 搜索资源失败，捕获异常
        console.error('获取资源数据失败:', error)
        return null 
    }
}
